package com.swak.consistency.reliablemsg.context;

import com.swak.annotation.ConsistencyScheme;
import com.swak.consistency.core.context.ConsistencyContext;

import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

/**
 * 可靠消息上下文
 * 
 * @author DELL
 */
@Getter
@Setter
@Accessors(chain = true)
public class ReliableMsgContext extends ConsistencyContext {

	/**
	 * 消息ID
	 */
	private Long msgId;

	/**
	 * 执行的阶段
	 */
	private Phase phase;

	/**
	 * 事务对象
	 */
	private ReliableMsgLog trans;
	
	/**
	 *  存储消息
	 */
	private boolean storeMsg;

	public ReliableMsgContext() {
		this.scheme = ConsistencyScheme.Reliable_Msg;
	}

	@Override
	public boolean isOpenTransaction() {
		return msgId != null;
	}

	/**
	 * 更新事务对象
	 * 
	 * @param trans
	 * @return
	 */
	public ReliableMsgContext update(ReliableMsgLog trans, Phase phase) {
		this.msgId = trans.getMsgId();
		this.phase = phase;
		this.trans = trans;
		return this;
	}
}
